package com.profgj.profgj.config;

import com.profgj.profgj.interceptor.SqlInjectInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * SpringMvc Web配置
 *
 * @author 杨帅
 * @since 2021-06-22 11:09:35
 */

/**
 * @Configuration 代表这个是一个配置类
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    /**
     * 静态资源处理
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

//        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");

    }

    /**
     * web 拦截器配置
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        // 将web注入一个SQL拦截器
        registry.addInterceptor(new SqlInjectInterceptor());
    }
}
